package ahpu.piconet.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import ahpu.piconet.domin.User;
import ahpu.piconet.service.UserService;

@Controller
public class UserAction {
	@Autowired
	private UserService userService;
	

	@RequestMapping(value = "/desktop")
	public String login(User u, Model m) throws Exception {
		System.out.println(u.getUsername());
		
		if (userService.login(u.getUsername()) != null) {
			User real = userService.login(u.getUsername());
			if (null != real && real.getPassword().equals(u.getPassword())) {
				return "/desktop";
			} else {
				m.addAttribute("msg", "密码错误!");
				return "login";
			}
		} else {
			m.addAttribute("msg", "用户名错误!");
			return "login";
		}
	}

	@RequestMapping(value = "/login")
	public String index() {
		return "login";
	}
	
	
}
